#! /usr/bin/env python

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import plotter as plt

use_plotter = 'tkinter'
pixel_size = (320,320)

def init(psize):
	global pixel_size
	plt.init(use_plotter, psize)
	pixel_size = psize

def show():
	plt.show()




class Plane:
	def __init__(self, size):
		self.size = size
		self.psize = pixel_size
		self.width, self.height = size
		self.pwidth, self.pheight = pixel_size
		self.center_width = self.pwidth / 2
		self.center_height = self.pheight / 2
		self.width_rate = self.pwidth / float(self.width)
		self.height_rate =  self.pheight / float(self.height)
		self.pplot = plt.create()

	def plot(self, *pointss):
		for points,colors in pointss:
			coloriter = colors.get(len(points))
			for xy in points:
				color = next(coloriter)
				nxy = self.convert(xy)
				self.pplot.append((nxy, color))

	def convert(self, xy):
		x,y = xy
		return (x*self.width_rate+self.center_width,
						-y*self.height_rate+self.center_height)

